<template>
  <div class="newsinfo-container">
    <!-- 新闻标题 -->
    <h3 class="title">{{ newsinfo.title }}</h3>
    <p class="info">
      <span>发布时间：{{ newsinfo.add_time | dateFormat }}</span>
      <span>点击：{{ newsinfo.click }}次</span>
    </p>
    <hr />
    <!-- 新闻内容 -->
    <div class="content" v-html="newsinfo.content"></div>

    <!-- 评论子组件 -->
    <comment :newsid="id"></comment>
  </div>
</template>

<script>
// 导入评论子组件
import comment from "../sub-components/Comment.vue";

export default {
  data() {
    return {
      newsinfo: {},
    };
  },
  created() {
    this.getNewsInfo();
  },
  methods: {
    async getNewsInfo() {
      const { data } = await this.$http.get("api/getnew/" + this.id);
      if (data.status === 0) {
        this.newsinfo = data.message[0];
      }
    },
  },
  props: ["id"],
  components: {
    comment, // 为当前的 NewsInfo.vue 组件注册私有的子组件
  },
};
</script>

<style lang="scss" scoped>
.newsinfo-container {
  padding: 3px;
  .title {
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
    color: red;
  }
  .info {
    display: flex;
    justify-content: space-between;
    color: #26a2ff;
  }
  .content {
  }
}
</style>